<!--suppress ALL -->
<div class="layui-fluid layui-anim website-anim" id="website-declareTopic" lay-title="资格审查"
     xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="declareTopic-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">课题名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input"
                                                   placeholder="请输入课题名称">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">主持人</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="leaderName" autocomplete="off" class="layui-input"
                                                   placeholder="请输入主持人">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">指南序号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="topicCode" autocomplete="off" class="layui-input"
                                                   placeholder="请输入指南序号">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">期次</label>
                                        <div class="layui-input-inline">
                                            <input type="text" class="layui-input" id="yearSearch" readonly name="yearSearch">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学科分类</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${subjectTypes}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">状态</label>
                                        <div class="layui-input-inline">
                                            <select name="statusTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${statusTypes}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="exportSummary">
                                    汇总表
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="exportIntention">
                                    意向表
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="declareTopicTable" lay-data="{id: 'declareTopicTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--表格中字典的显示-->
<script type="text/html" id="subjectType">
    {{#
    var dict=layui.dict.getByCode(d.subjectTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="researchType">
    {{#
    var dict=layui.dict.getByCode(d.researchTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="achievementFormType">
    {{#
    var dictList=layui.dict.getByCodes(d.achievementFormTypeCode ? d.achievementFormTypeCode.split(','): '');
    }}
    <span>
    {{# layui.each(dictList,function(index,item) { }}
    {{ item.name }}&nbsp;
    {{#  }); }}
    </span>
</script>
<script type="text/html" id="statusTypeCode">
    {{#
    var dict=layui.dict.getByCode(d.statusTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="leaderCompany">
    {{#  if(d.leader){ }}
    <span>{{ d.leader.company }}</span>
    {{#  } }}
</script>
<!--表格中状态的按钮-->
<script type="text/html" id="declareTopic-publish">
    <input type="checkbox" {{ d.isPublish ? 'checked' : '' }} value="{{d.declareTopicId}}" lay-filter="publish_status" lay-skin="switch" lay-text="发布|取消"/>
</script>
<!--表格中的操作栏-->
<script type="text/html" id="declareTopic-option">
    <a lay-event="detail" class="website-green" shiro:hasPermission="declareTopic:list">查看</a>
    {{# if (d.statusTypeCode === 'apply') { }}
    <a lay-event="check" class="website-red" shiro:hasPermission="declareTopic:check">审查</a>
    {{# } }}
</script>

<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'website', 'dict', 'laydate'], function () {
        var $ = layui.jquery,
                website = layui.website,
                form = layui.form,
                table = layui.table,
                dict = layui.dict,
                laydate = layui.laydate,
                dropdown = layui.dropdown,
            $view = $('#website-declareTopic'),
            $query = $view.find('#query'),
            $addNotice = $view.find('#addNotice'),
            $reset = $view.find('#reset'),
            $exportSummary = $view.find('#exportSummary'),
            $exportIntention = $view.find('#exportIntention'),
            $searchForm = $view.find('form'),
                sortObject = {field: 'createTime', type: null},
                tableIns,
                createTimeFrom,
                createTimeTo;
        form.render();
        //初始化年份的搜索框
        laydate.render({
            elem: '#yearSearch', //指定元素
            type: 'year',
            trigger: 'click',
            value: new Date()
        });
        initTable();
        /**
         * 发布按钮的点击事件
         */
        form.on('switch(publish_status)', function (obj) {
            website.post(ctx + 'declareTopic/publish/' + this.value, {isPublish: obj.elem.checked}, function () {
                website.alert.success('发布成功');
                    $query.click();
            });
        });

        /**
         * 搜索按钮旁边的更多，这个是下拉控件
         **/


        /**
         * table操作栏的按钮监听事件
         **/
        table.on('tool(declareTopicTable)', function (obj) {
            var data = obj.data,
                    layEvent = obj.event;
            if (layEvent === 'detail') {
                website.navigate('/biz/declareTopic/qualificationDetail/' + data.declareId);
            }
            if (layEvent === 'check') {
                website.modal.view('资格审查', 'biz/declareTopic/check/' + data.declareId, {
                    area: $(window).width() <= 750 ? '95%' : '50%'
                });
            }
        });

        /**
         * 表格的排序点击
         **/
        table.on('sort(declareTopicTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

            $query.on('click', function () {
        var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
        tableIns.reload({where: params, page: {curr: 1}});
        });
            $reset.on('click', function () {
            $searchForm[0].reset();
        sortObject.type = 'null';
        createTimeTo = null;
        createTimeFrom = null;
        tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });

            $exportSummary.on('click', function () {
        var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
        params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
        params.pageNum = $view.find(".layui-laypage-em").next().html();
        website.download(ctx + 'declareTopic/summary', params, '课题申报汇总表.xlsx');
        });

            $exportIntention.on('click', function () {
        var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
        params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
        params.pageNum = $view.find(".layui-laypage-em").next().html();
        website.download(ctx + 'declareTopic/intention', params, '课题意向登记表.xls');
        });
        /**
         * 初始化表格
         */
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'declareTopicTable',
                url: ctx + 'declareTopic/list',
                where: {yearSearch: new Date().getFullYear()},
                cols: [[
                    /*{type: 'checkbox'},*/
                    { type: 'numbers', title: '序号'},
                    {field: 'code', title: '课题编号', minWidth: 100},
                    {field: 'name', title: '课题名称', minWidth: 100},
                    {field: 'topicCode', title: '指南序号', minWidth: 100},
                    {field: 'subjectTypeName', title: '学科分类', templet: '#subjectType', minWidth: 100},
                    {field: 'researchTypeName', title: '研究类型',templet: '#researchType',  minWidth: 100},
                    {field: 'leaderName', title: '课题主持人',minWidth: 100},
                    {field: 'leaderCompany', title: '所在单位',templet: '#leaderCompany', minWidth: 100},
                    {field: 'achievementFormTypeName', title: '成果形式',templet: '#achievementFormType', minWidth: 100},
                    {field: 'statusTypeName', title: '审核状态',templet: '#statusTypeCode', minWidth: 100},
                    {title: '操作', toolbar: '#declareTopic-option', minWidth: 140}
                ]]
            });
        }

        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            return params;
        }
    })
</script>